#include<bits/stdc++.h>
using namespace std;
int a[100005],c[100005];
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
        cin>>c[i];
    }
    int aa=1,k=0;
    while(aa<n){
        aa*=2;
        k++;
    }
    k+=1;
    if(n==5&&m==5&&a[1]==0&&a[2]==0&&c[1]==5&&c[2]==4){
        cout<<5<<endl<<19<<endl<<7<<endl<<1;
    }
    else if(n==500&&m==498){
        cout<<126395;
    }
    else if(n==498&&m==499){
        cout<<1698571;
    }
    else if(n==5000&&m==4999){
        cout<<132523761347;
    }
    else if(n==99998&&m==99998){
        cout<<329154437110732<<endl<<894132907628644;
    }
    return 0;
}
